package com.hu._04_direct;

import com.hu.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

//消息发送者
public class Send {

    // DIRECT  定向发送  routingkey 匹配的

    //交换机的名字
    public static final String NAME_EXCHANGE_DIRECT = "name_exchange_direct";

    public static void main(String[] args) throws Exception {
        /*
         * 消费者前三步 获取连接对象 创建通道 创建队列 和发送者一摸一样
         * */
        //通过连接工具创建链接对象
        Connection connection = ConnectionUtil.getConnection();

        //连接对象 创建通道
        Channel channel = connection.createChannel();

        /** 创建交换机:定向   BuiltinExchangeType交换类型
         *  队列在消费者方创建了
         */
        channel.exchangeDeclare(NAME_EXCHANGE_DIRECT, BuiltinExchangeType.DIRECT);

        //5.发送消息
        String message = "A hello world message";
        //交换机  队列名(routingkey)   属性参数   消息内容
        channel.basicPublish(NAME_EXCHANGE_DIRECT,"delete",null,message.getBytes());
        System.out.println("消息发送完毕："+message);
    }

}
